package com.fengxing.ams.web.facade.mouble;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class BaseRedis {

	static JedisPoolConfig config = new JedisPoolConfig();
	
	protected static Gson gson = new GsonBuilder().create();
	
	protected static final String ENROLL_STUDENTS = "ENROLL_STUDENTS";
	protected static final String ENROLLMENTS = "ENROLLMENTS";
	protected static final String COLLEGE = "COLLEGE";
	protected static final String DESCRIPTION = "DESCRIPTION";
	protected static final String MAJOR = "MAJOR";
	protected static final String PLAN = "PLAN";
	
	static {
	    //最大空闲连接数, 应用自己评估，不要超过ApsaraDB for Redis每个实例最大的连接数
	    config.setMaxIdle(200);
	    //最大连接数, 应用自己评估，不要超过ApsaraDB for Redis每个实例最大的连接数
	    config.setMaxTotal(300);
//	    config.setTestOnBorrow(true);
//	    config.setTestOnReturn(true);
	}
	
	static JedisPool pool = new JedisPool(config, "127.0.0.1", 6379, 30000);
//	static JedisPool pool = new JedisPool(config, "0d1ad2347b104fd3.m.cnbja.kvstore.aliyuncs.com", 6379, 30000, "0d1ad2347b104fd3:ZXCVasdf1234");
	
	public Jedis getJedis() {
		return pool.getResource();
	}
	
	public void closeJedis(Jedis jedis) {
		pool.returnResource(jedis);
	}
	
}
